﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Silver3D.Math
{
    public static class ArrayParser
    {
        private static readonly char[] Separators = new char[] { ' ', '\n', '\t', ',', '[', ']', '(', ')', '{', '}' };

        private static string[] SplitArray(string array)
        {
            if (array == null) return null;
            string[] values = array.Split(Separators, StringSplitOptions.RemoveEmptyEntries);
            if (values.Length == 0) return null;
            return values;
        }

        public static double[] GetDoubleArray(string value)
        {
            string[] values = SplitArray(value);
            if (values == null) return null;

            double[] a = new double[values.Length];
            for (int i = 0; i < values.Length; ++i)
                a[i] = double.Parse(values[i].Trim());

            return a;
        }

        public static float[] GetFloatArray(string value)
        {
            string[] values = SplitArray(value);
            if (values == null) return null;

            float[] a = new float[values.Length];
            for (int i = 0; i < values.Length; ++i)
                a[i] = float.Parse(values[i].Trim());

            return a;
        }

        public static int[] GetIntArray(string value)
        {
            string[] values = SplitArray(value);
            if (values == null) return null;

            int[] a = new int[values.Length];
            for (int i = 0; i < values.Length; ++i)
                a[i] = int.Parse(values[i].Trim());

            return a;
        }
    }
}
